package com.sh.sales.happysales.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.sh.sales.happysales.R;
import com.sh.sales.happysales.app.AppCondig;
import com.sh.sales.happysales.app.AppContext;
import com.sh.sales.happysales.base.BaseActivity;
import com.sh.sales.happysales.service.LoginObserable;
import com.sh.sales.happysales.service.LoginObsever;
import com.sh.sales.happysales.view.NewToast;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPI;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by zhouyucheng on 2017/9/14.
 */

public class LoginActivity extends BaseActivity implements LoginObsever {
    private static String TAG = "LoginActivity";
    @BindView(R.id.happysale_logo)
    ImageView happysaleLogo;
    @BindView(R.id.wechart_login)
    Button wechartLogin;



    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        LoginObserable.getInstance().registerObserver(this);
        ButterKnife.bind(this);
    }

    @OnClick(R.id.wechart_login)
    public void onViewClicked(View view) {
         weixinLogin();
       // LoginUtil.getInstance().catchUserInfo("021ac0wb0R6Rgx1tRgvb0U9owb0ac0wC", LoginActivity.this, true);
    }

    private void weixinLogin() {
        IWXAPI mApi = AppContext.getIwxapi();
        mApi.registerApp(AppCondig.WX_APPID);
        if (mApi != null && mApi.isWXAppInstalled()) {
            SendAuth.Req req = new SendAuth.Req();
            req.scope = "snsapi_userinfo";
            req.state = "wechat_sdk_demo_test_neng";
            mApi.sendReq(req);
        } else {
            NewToast.makeText(this, "用户未安装微信");
        }
    }

    @Override
    public void refreshUserSign(int Position) {
        finish();
    }

    @Override
    protected void onDestroy() {
        LoginObserable.getInstance().unregisterObserver(this);
        super.onDestroy();
    }
}
